package org.softmed.rest.admin.resource;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import org.softmed.rest.admin.DetailLevelListener;
import org.softmed.rest.admin.DetailChooser.DetailLevel;
import org.softmed.rest.admin.httpMethods.DeleteConfig;
import org.softmed.rest.admin.httpMethods.HTTPMethodEditor;
import org.softmed.rest.admin.interfaces.FileHandler;
import org.softmed.rest.admin.interfaces.PathChangedListener;
import org.softmed.rest.admin.interfaces.SelectionPathChanged;
import org.softmed.rest.admin.module.ValidationException;

import restlet.description.convert.RESTResourceDescription;


public class ResourceMethodsManager extends JPanel implements
		SelectionPathChanged, PathChangedListener,DetailLevelListener {

	HTTPMethodEditor get = new HTTPMethodEditor();
	HTTPMethodEditor put = new HTTPMethodEditor();
	HTTPMethodEditor post = new HTTPMethodEditor();
	DeleteConfig delete = new DeleteConfig();
	RESTResourceDescription resourceDescription;

	public ResourceMethodsManager() {
//		setBackground(Color.YELLOW);
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		
//		setPreferredSize(new Dimension(540,25));
//		setMaximumSize(new Dimension(540,25));
		setMinimumSize(new Dimension(100, 25));
		
		
		
		get.setMethodName("Get");
		put.setMethodName("Put");
		post.setMethodName("Post");
		delete.setPathChangedListener(new PathChangedListener() {

			@Override
			public void pathChanged(String path) {
				resourceDescription.setDeleteHandler(path);

			}

		});
		
//		resourceDescription.get

		add(get);
		add(put);
		add(post);
		add(delete);
	}

	public void validateData() throws ValidationException {
		get.validateData();
		put.validateData();
		post.validateData();
		delete.validateData();

	}

	public void setResourceDescription(
			RESTResourceDescription resourceDescription) {
		this.resourceDescription = resourceDescription;
		delete.setResourceDescription(resourceDescription);

		get.setHandlers(resourceDescription.getGetHandlers());
		put.setHandlers(resourceDescription.getPutHandlers());
		post.setHandlers(resourceDescription.getPostHandlers());
	}

	public void selectionPathChanged(boolean directory, String name,
			String parent) {
		get.selectionPathChanged(directory, name, parent);
		put.selectionPathChanged(directory, name, parent);
		post.selectionPathChanged(directory, name, parent);
		delete.selectionPathChanged(directory, name, parent);

	}

	public void setFileHandler(FileHandler fileHandler) {
		get.setFileHandler(fileHandler);
		put.setFileHandler(fileHandler);
		post.setFileHandler(fileHandler);
		delete.setFileHandler(fileHandler);
	}

	@Override
	public void pathChanged(String path) {
		// TODO Auto-generated method stub

	}

	@Override
	public void detailLevelChanged(DetailLevel detailLevel) {
		get.detailLevelChanged(detailLevel);
		put.detailLevelChanged(detailLevel);
		post.detailLevelChanged(detailLevel);
		
	}

}
